// import axios from "axios";
import http from "@/api/index";

//自定义post请求
export function postRequest(url: string, data: any) {
  return http.post(url, data);
}

//自定义get请求
export function getRequest(url: string, data: any) {
  return http.get(url, data);
}

export function getDetails(url: string, id: String) {
  return http.get(url + "/get/" + id, {});
}

export function getByPath(url: string, id: String) {
  return http.get(url + "/" + id, {});
}

export function deleteOne(url: string, id: String) {
  return http.get(url + "/delete/" + id, {});
}

export function doDelete(url: string, data: any) {
  return http.post(url + "/delete", data);
}

export function doAdd(url: string, data: any) {
  return http.post(url + "/add", data);
}

export function doUpdate(url: string, data: any) {
  return http.post(url + "/update", data);
}

//自定义查询列表
export function getList(url: string, data: any) {
  return http.post(url + "/query", data);
}

//自定义查询列表
export function queryList(url: string, data: any) {
  return http.post(url, data);
}

export function exportFileUrl(url: string, data: any) {
  return http.post(url, data);
}

//附件上传
export function uploadUrl(url: string, data: any) {
  return http.post(url, data);
}

//下载文件
export function downloadFile(url: string, data: any) {
  return http.download(url, data);
}

//下载附件
export function downloadAttachment(attamentUuid: string) {
  return http.download(`/attachment/download/${attamentUuid}`, {});
}

/**
 * @description 表格高度（页面高度除去标签栏、操作栏、分页剩下的高度）
 * @returns {number}
 */
export function backTableHeight() {
  const height = document.documentElement.clientHeight;
  // return height - 90 - 96 - 130;
  return height - 316;
}
/**
 *
 * @returns 获取屏幕高度
 */
export function getClientHeight() {
  return document.documentElement.clientHeight;
}

/**
 *
 * @returns 获取数据为空的url
 */
export function getDataEmptyImg() {
  return new URL("/data_empty.png", import.meta.url).href;
}

export function getImgUrl(imgUrl: string) {
  return new URL(imgUrl, import.meta.url).href;
}

//枚举数据本地缓存
export function getLocalStorage() {
  return JSON.parse(String(localStorage.getItem("localStorageEnumData")));
}

//排序
export function doSorted(val: any, data: any) {
  if (val.prop) {
    if (val.order == "descending") {
      data.sorts = `${val.prop}@desc`;
    } else {
      data.sorts = `${val.prop}@asc`;
    }
  }
}
